/* FOR DETAILED DESCRIPTION OF .DTA AND .DO FILES, SEE README.PDF */

********************************
// INSTALL USER WRITTEN COMMANDS: 
net install grc1leg.pkg, replace from(http://www.stata.com/users/vwiggins/) // GRAPHS WITH COMMON LEGEND
net install egenmore.pkg, replace from(http://fmwww.bc.edu/RePEc/bocode/e/) // ADDITIONAL EGEN FUNCTIONS
********************************


clear all 

// SET MAIN PATH //
global PATH "~/Dropbox/solar_misallocation/submission_data"
cd ${PATH}

********************************
// (0) AUXILARY FILES // 
********************************

do ${PATH}/programs/1_AS_regressions.do			// ONLINE APPENDIX (OA): Figures B.1 and B.2, Tables B.1 - B.3, Input for Tables B.4 and B.5
do ${PATH}/programs/1_lambdas.do 				// Input for Table 1 (marginal benefits), Figure 3, OA: Table A.1, D.1
do ${PATH}/programs/1_lambdas_lpollution.do  	// INCLUDES CO-POLLUTANTS (see OA: Section A.2), Input for Table 1 (marginal benefits)

* ROBUSTNESS: ALTERNATIVE VERSIONS OF FILE LAMBDAS_V1.DO FOR GERMANY-WIDE DISPATCH
do ${PATH}/programs/1_lambdas_robust2.do 		// OA: Table A.2
do ${PATH}/programs/1_lambdas_lpollution_robust2.do  // INCLUDES CO-POLLUTANTS

do ${PATH}/programs/3_Supply_Demand_splitTenneT.do  	// Table 2, OA: Figures A.2, D.6, Table D.3




********************************
// (1) MAIN REALLOCATION (RESIDENTIAL SOLAR)
********************************

* ATTENTION: files are slow to run as they loop though different reallocation routines, individual do files are commented

************
// GLOBALS

// STEP SIZE FOR REALLOCATION: TOTAL RESIDENTIAL SOLAR CAPACITY 5728 MW (2016): USE INTEGER OF TOTAL CAPACITY FOR "FULL" REALLOCATION
global step_size = 32 

// GAMMA RANGE
global gamma_min = 0.05
global gamma_max = 0.5
global gamma_delta = 0.05
************

do ${PATH}/programs/2_ini_reallocation_main.do  // CALLS SUBROUTINES FOR REALLOCATION
// Figures 4 and 5
// OA: Figures D.4



********************************
// (2) REALLOCATION OF TOTAL SOLAR CAPACITY, TAKING INTO ACCOUNT N-S TRANSMISSION
********************************

************
// UPDATE GLOBALS FOR REALLOCATION OF TOTAL SOLAR PV CAPACITY
// TOTAL SOLAR CAPACITY 40509 MW (2016): USE INTEGER OF TOTAL CAPACITY FOR "FULL" REALLOCATION
global step_size = 63

// GAMMA RANGE
global gamma_min = 0.2 // for Figure 7: additional data points (interpolated between): 0.475
global gamma_max = 0.8 // for Figure 7: additional data points (interpolated between): 0.625
global gamma_delta = 0.05

// TRANSMISSION CAPACITY RANGE
global deltaK_min 	0 
global deltaK_max 	6000 
global deltaK_inc 	2000 

// SCC 
global SCC = 31.71

************

do ${PATH}/programs/3_PVoutput_analysis_all_splitTenneTdeltaK.do  
// Figure 7 
// OA: Figures D.7
